package cn.com.cifi.mars.service.impl;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.cifi.mars.bean.bo.MdmBuildAreaBO;
import cn.com.cifi.mars.bean.bo.PanoPlanCastDecisionBO;
import cn.com.cifi.mars.bean.vo.price.PriceValueCompareVO;
import cn.com.cifi.mars.common.exception.MsgException;
import cn.com.cifi.mars.constant.CodeEnum;
import cn.com.cifi.mars.constant.Constants;
import cn.com.cifi.mars.constant.IsDeleteEnum;
import cn.com.cifi.mars.constant.ModuleTypeEunm;
import cn.com.cifi.mars.constant.OrgTypeEunm;
import cn.com.cifi.mars.constant.ProcessingModeEnum;
import cn.com.cifi.mars.constant.ProcessingStateEnum;
import cn.com.cifi.mars.constant.VersionCreateEnum;
import cn.com.cifi.mars.constant.VersionEventEnum;
import cn.com.cifi.mars.constant.VersionStatusEnum;
import cn.com.cifi.mars.constant.VersionTypeEunm;
import cn.com.cifi.mars.constant.WhetherEnum;
import cn.com.cifi.mars.entity.MdmStage;
import cn.com.cifi.mars.entity.PanoplanBuildPlanItem;
import cn.com.cifi.mars.entity.PriceValueOrg;
import cn.com.cifi.mars.entity.PriceVersion;
import cn.com.cifi.mars.entity.PriceVersionBackups;
import cn.com.cifi.mars.entity.ProjectLockRecordDetail;
import cn.com.cifi.mars.entity.SysNotice;
import cn.com.cifi.mars.entity.common.IdmUser;
import cn.com.cifi.mars.mapper.mars.PriceValueOrgMapper;
import cn.com.cifi.mars.mapper.mars.PriceVersionMapper;
import cn.com.cifi.mars.mapper.mars.ProjectLockRecordDetailMapper;
import cn.com.cifi.mars.service.BuildAreaService;
import cn.com.cifi.mars.service.PanoplanBuildPlanService;
import cn.com.cifi.mars.service.PriceValueOrgService;
import cn.com.cifi.mars.service.PriceVersionBackupsService;
import cn.com.cifi.mars.service.PriceVersionService;
import cn.com.cifi.mars.service.PriceVersionValueOrgService;
import cn.com.cifi.mars.service.ProjectLockRecordDetailService;
import cn.com.cifi.mars.service.ProjectLockRecordService;
import cn.com.cifi.mars.service.SignPlanVersionService;
import cn.com.cifi.mars.service.StageService;
import cn.com.cifi.mars.service.SupplyPlanVersionService;
import cn.com.cifi.mars.service.SysNoticeService;
import cn.com.cifi.mars.service.VersionLogService;
import cn.com.cifi.mars.util.StrUtils;
import cn.com.cifi.mars.util.UUIDUtils;
import cn.com.cifi.mars.util.VersionNameUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 项目锁定详情表 服务实现类
 * </p>
 *
 * @author plx
 * @since 2020-05-22
 */
@Service
@Slf4j
public class ProjectLockRecordDetailServiceImpl extends ServiceImpl<ProjectLockRecordDetailMapper, ProjectLockRecordDetail> implements ProjectLockRecordDetailService {

    @Autowired
    private ProjectLockRecordService projectLockRecordService;

    @Autowired
    private PriceVersionMapper priceVersionMapper;

    @Autowired
    private PriceVersionValueOrgService priceVersionValueOrgService;

    @Autowired
    private PriceVersionValueOrgServiceImpl priceVersionValueOrgServiceImpl;

    @Autowired
    private SupplyPlanVersionService supplyPlanVersionService;

    @Autowired
    private SignPlanVersionService signPlanVersionService;

    @Autowired
    private BuildAreaService buildAreaService;

    @Autowired
    private PanoplanBuildPlanService panoplanBuildPlanService;

    @Autowired
    private PriceVersionService priceVersionService;

    @Autowired
    private StageService stageService;

    @Autowired
    private PriceValueOrgService priceValueOrgService;

    @Autowired
    private PriceValueOrgMapper priceValueOrgMapper;

    @Autowired
    private PriceVersionBackupsService priceVersionBackupsService;

    @Autowired
    private SysNoticeService sysNoticeService;

    @Autowired
    private VersionLogService versionLogService;

    @Autowired
    private ProjectLockRecordDetailService projectLockRecordDetailService;

    @Override
    public void refreshPriceVersion(String projectId, String projectCode, String schemeId, String instId, JSONArray areaItems) {
        LocalDateTime now = LocalDateTime.now();
        Set<String> stageIds = new HashSet<String>();
        Set<String> bldPrdIds = new HashSet<String>();
        List<ProjectLockRecordDetail> projectLockRecordDetails = new ArrayList<ProjectLockRecordDetail>();
        Map<String, List<ProjectLockRecordDetail>> stageRecordDetailMap = new HashMap<String, List<ProjectLockRecordDetail>>();
        if (CollectionUtils.isNotEmpty(areaItems)){
            for (int i = 0; i < areaItems.size(); i++) {
                JSONObject areaItem = areaItems.getJSONObject(i);
                ProjectLockRecordDetail projectLockRecordDetail = new ProjectLockRecordDetail();
                projectLockRecordDetail.setId(UUIDUtils.create());
                projectLockRecordDetail.setRecordId(UUIDUtils.create());
                projectLockRecordDetail.setSchemeId(schemeId);
                projectLockRecordDetail.setProjectId(projectId);
                projectLockRecordDetail.setProjectCode(projectCode);
                String stageId = areaItem.getString("stageId");
                projectLockRecordDetail.setStageId(stageId);
                projectLockRecordDetail.setStageCode(areaItem.getString("stageCode"));
                String bldPrdId = areaItem.getString("bldPrdId");
                projectLockRecordDetail.setBldPrdId(bldPrdId);
                projectLockRecordDetail.setIsParking(StrUtils.stringToInteger(areaItem.getString("isParking")));
                projectLockRecordDetail.setName(areaItem.getString("name"));
                projectLockRecordDetail.setType(areaItem.getString("type"));
                projectLockRecordDetail.setNum(StrUtils.stringToInteger(areaItem.getString("num")));
                projectLockRecordDetail.setArea(StrUtils.stringToBigDecimal(areaItem.getString("area")));
                projectLockRecordDetail.setAveragePrice(StrUtils.stringToBigDecimal(areaItem.getString("averagePrice")));
                projectLockRecordDetail.setPrice(StrUtils.stringToBigDecimal(areaItem.getString("price")));
                projectLockRecordDetail.setCreateTime(now);
                projectLockRecordDetail.setUpdateTime(now);
                projectLockRecordDetails.add(projectLockRecordDetail);

                stageIds.add(stageId);
                bldPrdIds.add(bldPrdId);

                List<ProjectLockRecordDetail> projectLockRecordDetailsList = stageRecordDetailMap.get(stageId);
                if(CollectionUtils.isEmpty(projectLockRecordDetailsList)){
                    projectLockRecordDetailsList = new ArrayList<ProjectLockRecordDetail>();
                }
                projectLockRecordDetailsList.add(projectLockRecordDetail);
                stageRecordDetailMap.put(stageId, projectLockRecordDetailsList);
            }

            if(CollectionUtils.isNotEmpty(projectLockRecordDetails)){
                try{
                    projectLockRecordDetailService.saveBatch(projectLockRecordDetails);
                }catch (Exception e){
                    log.error("####################     refreshPriceVersion    projectLockRecordDetailService:"+e.getMessage(), e);
                }
            }

            if (CollectionUtils.isNotEmpty(stageIds)){
                for (String stageId : stageIds){
                    Map<String, List<ProjectLockRecordDetail>> projectLockRecordDetailMap = new HashMap<String, List<ProjectLockRecordDetail>>();
                    List<ProjectLockRecordDetail> recordDetails = stageRecordDetailMap.get(stageId);
                    for (ProjectLockRecordDetail projectLockRecordDetail : recordDetails){
                        String bldPrdId = projectLockRecordDetail.getBldPrdId();
                        List<ProjectLockRecordDetail> projectLockRecordDetailList = projectLockRecordDetailMap.get(bldPrdId);
                        if (CollectionUtils.isEmpty(projectLockRecordDetailList)){
                            projectLockRecordDetailList = new ArrayList<ProjectLockRecordDetail>();
                        }
                        projectLockRecordDetailList.add(projectLockRecordDetail);
                        projectLockRecordDetailMap.put(bldPrdId, projectLockRecordDetailList);
                    }
                    //查询指定分期信息
                    MdmStage mdmStage = stageService.selectById(stageId);
                    if(mdmStage == null){
                        throw new MsgException(CodeEnum.STAGE_NON_EXISTENT);
                    }

                    PriceVersion recordPriceVersion = priceVersionService.getNewestPriceVersion(stageId);
                    if (recordPriceVersion != null){
                        String versionType = recordPriceVersion.getVersionType();
                        String versionState = recordPriceVersion.getVersionState();

                        planValueRecordRefreshOrCreate(instId, now, bldPrdIds, stageId, projectLockRecordDetailMap, mdmStage, recordPriceVersion, versionType, versionState);
                    }
                }
            }
        }

        //解锁
        projectLockRecordService.update(projectId, projectCode, schemeId, areaItems.toString());

        //刷新待办信息
        try{
            recordNoticeRefreshToUnlock(projectId, now);
        }catch (Exception e){
            log.error("###################    recordNoticeRefreshToUnlock   error:"+e.getMessage(), e);
        }

        log.info("####################    refreshPriceVersion    end:"+LocalDateTime.now());
    }

    public void planValueRecordRefreshOrCreate(String instId, LocalDateTime now, Set<String> bldPrdIds, String stageId, Map<String, List<ProjectLockRecordDetail>> projectLockRecordDetailMap, MdmStage mdmStage, PriceVersion recordPriceVersion, String versionType, String versionState) {
        try{
            //如果货值版本是动态版，则按需处理。如果不是动态版，则复制生成动态版
            if (StringUtils.isNotEmpty(versionType) && versionType.equals(VersionTypeEunm.DYNAMIC.getKey())){
                //归属年月
                int year = now.getYear();
                Month month = now.getMonth();
                int day = now.getDayOfMonth();
                int hour = now.getHour();

                LocalDate ascriptionDate = recordPriceVersion.getAscriptionDate();
                int ascriptionyear = ascriptionDate.getYear();
                Month ascriptionmonth = ascriptionDate.getMonth();

                //判断归属年月是否相同
                if(ascriptionyear == year && ascriptionmonth.equals(month)){
                    versionStatusJudgeInfo(instId, now, bldPrdIds, stageId, projectLockRecordDetailMap, mdmStage, recordPriceVersion, versionType, versionState, ascriptionDate);
                }else{
                    if (day == Constants.ONE && hour <= Constants.SIX) {//一号6点前
                        versionStatusJudgeInfo(instId, now, bldPrdIds, stageId, projectLockRecordDetailMap, mdmStage, recordPriceVersion, versionType, versionState, ascriptionDate);
                    }else{
                        String versionId = sysAppointPlanCreateInfo(now, bldPrdIds, stageId, projectLockRecordDetailMap, mdmStage, recordPriceVersion, LocalDate.now(), instId);

                        supplyPlanVersionService.createSupplyPlanVersion(versionId, VersionTypeEunm.DYNAMIC.getKey(), Constants.SYS);
                    }
                }
            }else{
                String versionId = sysAppointPlanCreateInfo(now, bldPrdIds, stageId, projectLockRecordDetailMap, mdmStage, recordPriceVersion, LocalDate.now(), instId);

                supplyPlanVersionService.createSupplyPlanVersion(versionId, VersionTypeEunm.DYNAMIC.getKey(), Constants.SYS);
            }
        }catch (Exception e){
            log.error("#########################        refreshPriceVersion    error:"+e.getMessage(), e);
        }
    }

    private void versionStatusJudgeInfo(String instId, LocalDateTime now, Set<String> bldPrdIds, String stageId, Map<String, List<ProjectLockRecordDetail>> projectLockRecordDetailMap, MdmStage mdmStage, PriceVersion recordPriceVersion, String versionType, String versionState, LocalDate ascriptionDate) {
        if (versionState.equals(VersionStatusEnum.SUCCESSAPPROVED.getKey())){
            String versionId = sysAppointPlanCreateInfo(now, bldPrdIds, stageId, projectLockRecordDetailMap, mdmStage, recordPriceVersion, ascriptionDate, instId);

            supplyPlanVersionService.createSupplyPlanVersion(versionId, VersionTypeEunm.DYNAMIC.getKey(), Constants.SYS);
        }else if (versionState.equals(VersionStatusEnum.SYSGENERATION.getKey())) {
            //查看货值版本是否有被供货确认使用
            boolean isComfirm = supplyPlanVersionService.supplyIsComfirm(recordPriceVersion.getId());
            if (isComfirm){
                //货值自动生成新版本
                String versionId = sysAppointPlanCreateInfo(now, bldPrdIds, stageId, projectLockRecordDetailMap, mdmStage, recordPriceVersion, ascriptionDate, instId);

                supplyPlanVersionService.createSupplyPlanVersion(versionId, VersionTypeEunm.DYNAMIC.getKey(), Constants.SYS);
            }else {
                //查看货值版本是否有被签约使用
                Map<String, Boolean> signMap = signPlanVersionService.priceBoolean(Arrays.asList(recordPriceVersion.getId()));
                Boolean isSign = signMap.get(recordPriceVersion.getId());
                if (isSign) {
                    //货值自动生成新版本
                    String versionId = sysAppointPlanCreateInfo(now, bldPrdIds, stageId, projectLockRecordDetailMap, mdmStage, recordPriceVersion, ascriptionDate, instId);

                    supplyPlanVersionService.createSupplyPlanVersion(versionId, VersionTypeEunm.DYNAMIC.getKey(), Constants.SYS);
                } else {
                    //查看货值版本是否封板
                    Integer isFinalization = recordPriceVersion.getIsFinalization();
                    if (isFinalization != null && isFinalization.equals(IsDeleteEnum.YES.getKey())) {
                        //货值自动生成新版本
                        String versionId = sysAppointPlanCreateInfo(now, bldPrdIds, stageId, projectLockRecordDetailMap, mdmStage, recordPriceVersion, ascriptionDate, instId);

                        supplyPlanVersionService.createSupplyPlanVersion(versionId, VersionTypeEunm.DYNAMIC.getKey(), Constants.SYS);
                    }else{

                        priceValueRefreshRecordInfo(stageId, recordPriceVersion, bldPrdIds,null, "record", null ,projectLockRecordDetailMap);

                        supplyPlanVersionService.createSupplyPlanVersion(recordPriceVersion.getId(), versionType, Constants.SYS);
                    }
                }
            }
        }else {
            //货值刷新
            priceValueRefreshRecordInfo(stageId, recordPriceVersion, bldPrdIds,null, "record", null, projectLockRecordDetailMap);
        }
    }

    public void priceValueRefreshRecordInfo(String projectFid, PriceVersion oldPriceVersion, Set<String> bldPrdIds, String instId, String source, List<PriceValueCompareVO> isDifferenceList, Map<String, List<ProjectLockRecordDetail>> projectLockRecordDetailMap) {
        log.info("###########################    priceValueRefresh start:"+LocalDateTime.now());
        LocalDateTime now = LocalDateTime.now();
        try{
            oldPriceVersion.setVersionLable(7);
            oldPriceVersion.setRemake("规划货值调整");
            oldPriceVersion.setUpdateTime(now);

            PriceVersionBackups priceVersionBackups = new PriceVersionBackups();
            BeanUtils.copyProperties(oldPriceVersion, priceVersionBackups);
            priceVersionBackups.setVersionId(oldPriceVersion.getId());
            priceVersionBackups.setId(UUIDUtils.create());

            //复制分期
            QueryWrapper<PriceValueOrg> stageQueryWrapper = new QueryWrapper<PriceValueOrg>();
            stageQueryWrapper.eq("version_id", oldPriceVersion.getId())
                    .eq("type", OrgTypeEunm.ORG_STAGE.getKey())
                    .eq("is_delete", IsDeleteEnum.NO.getKey());
            PriceValueOrg recordStageOrg = priceValueOrgService.getOne(stageQueryWrapper);
            PriceValueOrg stageOrg = new PriceValueOrg();
            BeanUtils.copyProperties(recordStageOrg, stageOrg);
            stageOrg.setUpdateTime(now);
            initBuildBasicInfo(stageOrg);

            //复制组团
            Map<String, PriceValueOrg> groupInsertMap = new HashMap<String, PriceValueOrg>();
            QueryWrapper<PriceValueOrg> groupQueryWrapper = new QueryWrapper<PriceValueOrg>();
            groupQueryWrapper.eq("version_id", oldPriceVersion.getId())
                    .eq("type", OrgTypeEunm.ORG_GROUP.getKey())
                    .eq("is_delete", IsDeleteEnum.NO.getKey());
            List<PriceValueOrg> recordGroupOrgs = priceValueOrgService.list(groupQueryWrapper);
            for (PriceValueOrg recordGroupOrg : recordGroupOrgs){
                PriceValueOrg groupOrg = new PriceValueOrg();
                BeanUtils.copyProperties(recordGroupOrg, groupOrg);
                groupOrg.setUpdateTime(now);
                initBuildBasicInfo(groupOrg);

                groupInsertMap.put(recordGroupOrg.getId(), groupOrg);
            }

            //复制产品构成
            Map<String, PriceValueOrg> productInsertMap = new HashMap<String, PriceValueOrg>();
            QueryWrapper<PriceValueOrg> productQueryWrapper = new QueryWrapper<PriceValueOrg>();
            productQueryWrapper.eq("version_id", oldPriceVersion.getId())
                    .eq("type", OrgTypeEunm.ORG_PRODUCT.getKey())
                    .eq("is_delete", IsDeleteEnum.NO.getKey());
            List<PriceValueOrg> recordProductOrgs = priceValueOrgService.list(productQueryWrapper);
            for (PriceValueOrg recordProductOrg : recordProductOrgs){
                PriceValueOrg productOrg = new PriceValueOrg();
                BeanUtils.copyProperties(recordProductOrg, productOrg);
                productOrg.setUpdateTime(now);
                initBuildBasicInfo(productOrg);

                PriceValueOrg groupOrg = groupInsertMap.get(recordProductOrg.getPid());
                productOrg.setPid(groupOrg.getId());

                productInsertMap.put(recordProductOrg.getId(), productOrg);
            }

            //复制面积段和车位
            Map<String, List<PriceValueOrg>> otherItemMap = new HashMap<String, List<PriceValueOrg>>();
            QueryWrapper<PriceValueOrg> otherQueryWrapper = new QueryWrapper<PriceValueOrg>();
            otherQueryWrapper.eq("version_id", oldPriceVersion.getId())
                    .in("type", OrgTypeEunm.ORG_HOUSE_PACKAGE.getKey(),OrgTypeEunm.ORG_SALE_PACKAGE.getKey(),
                            OrgTypeEunm.ORG_NOT_SALE_PACKAGE.getKey(),OrgTypeEunm.ORG_SALING_PARKING.getKey(),OrgTypeEunm.ORG_NOT_SALING_PARKING.getKey())
                    .eq("is_delete", IsDeleteEnum.NO.getKey());
            List<PriceValueOrg> recordOtherOrgs = priceValueOrgService.list(otherQueryWrapper);
            if(CollectionUtils.isNotEmpty(recordOtherOrgs)){
                for (PriceValueOrg recordOtherOrg : recordOtherOrgs){
                    PriceValueOrg otherOrg = new PriceValueOrg();
                    BeanUtils.copyProperties(recordOtherOrg, otherOrg);
                    otherOrg.setUpdateTime(now);

                    List<PriceValueOrg> orgList = otherItemMap.get(otherOrg.getPid());
                    if (CollectionUtils.isEmpty(orgList)){
                        orgList = new ArrayList<PriceValueOrg>();
                    }
                    orgList.add(otherOrg);
                    otherItemMap.put(otherOrg.getPid(), orgList);
                }
            }

            //复制楼栋
            Map<String, PriceValueOrg> buildItemMap = new HashMap<String, PriceValueOrg>();
            QueryWrapper<PriceValueOrg> buildQueryWrapper = new QueryWrapper<PriceValueOrg>();
            buildQueryWrapper.eq("version_id", oldPriceVersion.getId())
                    .eq("type", OrgTypeEunm.ORG_BUILD.getKey())
                    .eq("is_delete", IsDeleteEnum.NO.getKey());
            List<PriceValueOrg> recordBuildOrgs = priceValueOrgService.list(buildQueryWrapper);
            for (PriceValueOrg recordBuildOrg : recordBuildOrgs){
                PriceValueOrg buildOrg = new PriceValueOrg();
                PropertyUtils.copyProperties(buildOrg, recordBuildOrg);
                buildOrg.setUpdateTime(now);

                PriceValueOrg productOrg = productInsertMap.get(recordBuildOrg.getPid());
                buildOrg.setPid(productOrg.getId());

                buildItemMap.put(recordBuildOrg.getOrgId(), buildOrg);
            }

            List<PriceValueOrg> buildInsertList =new ArrayList<PriceValueOrg>();
            List<PriceValueOrg> otherInsertList = new ArrayList<PriceValueOrg>();
            Map<String, PriceValueOrg> buildInsertMap = new HashMap<String, PriceValueOrg>();
            for (Map.Entry<String, PriceValueOrg> buildItemmap : buildItemMap.entrySet()){

                PriceValueOrg buildOrg = buildItemmap.getValue();
                String buildId = buildOrg.getId();
                String buildOrgId = buildOrg.getOrgId();
                Integer buildIsParking = buildOrg.getIsParking();

                if(!bldPrdIds.contains(buildOrgId)){
                    buildInsertMap.put(buildOrgId, buildOrg);

                    List<PriceValueOrg> orgList = otherItemMap.get(buildOrg.getId());
                    if(CollectionUtils.isNotEmpty(orgList)){
                        for (PriceValueOrg org : orgList){
                            org.setId(UUIDUtils.create());
                            org.setVersionId(buildOrg.getVersionId());
                            org.setPid(buildId);
                            org.setUpdateTime(now);

                            otherInsertList.add(org);
                        }
                    }
                    continue;
                }

                //刷新规划货值
                List<ProjectLockRecordDetail> recordDetailList = projectLockRecordDetailMap.get(buildOrg.getOrgId());
                if (CollectionUtils.isNotEmpty(recordDetailList)) {

                    Integer collectTotalNum = 0;
                    Integer collectTotalSaleNum = 0;
                    BigDecimal collectTotalArea = new BigDecimal(0);
                    BigDecimal collectTotalPrice = new BigDecimal(0);

                    for (ProjectLockRecordDetail projectLockRecordDetail : recordDetailList){
                        PriceValueOrg otherOrg = new PriceValueOrg();
                        otherOrg.setId(UUIDUtils.create());
                        otherOrg.setVersionId(buildOrg.getVersionId());
                        otherOrg.setPid(buildId);
                        otherOrg.setType(projectLockRecordDetail.getType());

                        if (buildIsParking.equals(IsDeleteEnum.NO.getKey())){
                            if(projectLockRecordDetail.getType().equals(OrgTypeEunm.ORG_HOUSE_PACKAGE.getKey())){
                                otherOrg.setOrgCode(OrgTypeEunm.ORG_HOUSE_PACKAGE.getKey());
                                otherOrg.setOrgName(projectLockRecordDetail.getName());
                                otherOrg.setAreaPart(projectLockRecordDetail.getName());
                                otherOrg.setNum(projectLockRecordDetail.getNum());
                                otherOrg.setRoomNum(projectLockRecordDetail.getNum());
                                otherOrg.setSaleArea(projectLockRecordDetail.getArea());
                                otherOrg.setAveragePriceHouse(projectLockRecordDetail.getAveragePrice());
                                otherOrg.setHouseCommodityValue(projectLockRecordDetail.getPrice());
                                otherOrg.setIsParking(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsDelete(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsSplit(IsDeleteEnum.NO.getKey());
                                otherOrg.setTotalNum(projectLockRecordDetail.getNum());
                                otherOrg.setTotalSaleArea(projectLockRecordDetail.getArea());
                                otherOrg.setCreateTime(now);
                                otherOrg.setUpdateTime(now);

                                otherInsertList.add(otherOrg);

                                collectTotalNum = collectTotalNum + projectLockRecordDetail.getNum();
                                collectTotalArea = StrUtils.BigDecimalADD(collectTotalArea, projectLockRecordDetail.getArea());
                                collectTotalPrice = StrUtils.BigDecimalADD(collectTotalPrice, projectLockRecordDetail.getPrice());
                            }
                        }else{
                            if(projectLockRecordDetail.getType().equals(OrgTypeEunm.ORG_SALE_PACKAGE.getKey())){
                                otherOrg.setOrgCode(OrgTypeEunm.ORG_SALE_PACKAGE.getKey());
                                otherOrg.setOrgName(OrgTypeEunm.ORG_SALE_PACKAGE.getValue());
                                otherOrg.setIsSale(IsDeleteEnum.YES.getKey());
                                otherOrg.setNum(projectLockRecordDetail.getNum());
                                otherOrg.setParkingNum(projectLockRecordDetail.getNum());
                                otherOrg.setAveragePriceParking(projectLockRecordDetail.getAveragePrice());
                                otherOrg.setNotCommodityValue(projectLockRecordDetail.getPrice());
                                otherOrg.setPrice(projectLockRecordDetail.getPrice());
                                otherOrg.setPriceSold(projectLockRecordDetail.getPrice());
                                otherOrg.setParkingSold(projectLockRecordDetail.getNum());
                                otherOrg.setIsParking(IsDeleteEnum.YES.getKey());
                                otherOrg.setIsDelete(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsSplit(IsDeleteEnum.NO.getKey());
                                otherOrg.setCreateTime(now);
                                otherOrg.setUpdateTime(now);

                                collectTotalNum = collectTotalNum + projectLockRecordDetail.getNum();
                                collectTotalSaleNum = collectTotalSaleNum + projectLockRecordDetail.getNum();

                                otherOrg.setTotalNum(collectTotalNum);
                                otherInsertList.add(otherOrg);

                                collectTotalPrice = StrUtils.BigDecimalADD(collectTotalPrice, projectLockRecordDetail.getPrice());

                                buildOrg.setParkingSold(projectLockRecordDetail.getNum());
                                buildOrg.setPrice(StrUtils.BigDecimalADD(buildOrg.getPrice(), projectLockRecordDetail.getPrice()));
                                buildOrg.setPriceSold(projectLockRecordDetail.getPrice());

                            }else if(projectLockRecordDetail.getType().equals(OrgTypeEunm.ORG_NOT_SALE_PACKAGE.getKey())){
                                otherOrg.setOrgCode(OrgTypeEunm.ORG_NOT_SALE_PACKAGE.getKey());
                                otherOrg.setOrgName(OrgTypeEunm.ORG_NOT_SALE_PACKAGE.getValue());
                                otherOrg.setIsSale(IsDeleteEnum.NO.getKey());
                                otherOrg.setNum(projectLockRecordDetail.getNum());
                                otherOrg.setParkingNum(projectLockRecordDetail.getNum());
                                otherOrg.setAveragePriceParking(projectLockRecordDetail.getAveragePrice());
                                otherOrg.setNotCommodityValue(projectLockRecordDetail.getPrice());
                                otherOrg.setPrice(projectLockRecordDetail.getPrice());
                                otherOrg.setPricePriced(projectLockRecordDetail.getPrice());
                                otherOrg.setParkingPriced(projectLockRecordDetail.getNum());
                                otherOrg.setIsParking(IsDeleteEnum.YES.getKey());
                                otherOrg.setIsDelete(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsSplit(IsDeleteEnum.NO.getKey());
                                otherOrg.setCreateTime(now);
                                otherOrg.setUpdateTime(now);

                                collectTotalNum = collectTotalNum + projectLockRecordDetail.getNum();
                                collectTotalSaleNum = collectTotalSaleNum + projectLockRecordDetail.getNum();

                                otherOrg.setTotalNum(collectTotalNum);
                                otherInsertList.add(otherOrg);

                                collectTotalPrice = StrUtils.BigDecimalADD(collectTotalPrice, projectLockRecordDetail.getPrice());

                                buildOrg.setParkingPriced(projectLockRecordDetail.getNum());
                                buildOrg.setPrice(StrUtils.BigDecimalADD(buildOrg.getPrice(), projectLockRecordDetail.getPrice()));
                                buildOrg.setPricePriced(projectLockRecordDetail.getPrice());
                            }else if(projectLockRecordDetail.getType().equals(OrgTypeEunm.ORG_SALING_PARKING.getKey())){
                                otherOrg.setOrgCode(OrgTypeEunm.ORG_SALING_PARKING.getKey());
                                otherOrg.setOrgName(OrgTypeEunm.ORG_SALING_PARKING.getValue());
                                otherOrg.setNum(projectLockRecordDetail.getNum());
                                otherOrg.setParkingNum(projectLockRecordDetail.getNum());
                                otherOrg.setAveragePriceParking(projectLockRecordDetail.getAveragePrice());
                                otherOrg.setNotCommodityValue(projectLockRecordDetail.getPrice());
                                otherOrg.setIsParking(IsDeleteEnum.YES.getKey());
                                otherOrg.setIsDelete(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsSplit(IsDeleteEnum.NO.getKey());
                                otherOrg.setCreateTime(now);
                                otherOrg.setUpdateTime(now);

                                collectTotalNum = collectTotalNum + projectLockRecordDetail.getNum();
                                collectTotalSaleNum = collectTotalSaleNum + projectLockRecordDetail.getNum();
                                collectTotalPrice = StrUtils.BigDecimalADD(collectTotalPrice, projectLockRecordDetail.getPrice());

                                otherOrg.setTotalNum(collectTotalNum);
                                otherInsertList.add(otherOrg);

                            }else if (projectLockRecordDetail.getType().equals(OrgTypeEunm.ORG_NOT_SALING_PARKING.getKey())){
                                otherOrg.setOrgCode(OrgTypeEunm.ORG_NOT_SALING_PARKING.getKey());
                                otherOrg.setOrgName(OrgTypeEunm.ORG_NOT_SALING_PARKING.getValue());
                                otherOrg.setNum(projectLockRecordDetail.getNum());
                                otherOrg.setAveragePriceParkingForsale(projectLockRecordDetail.getAveragePrice());
                                otherOrg.setForsaleParkingNum(projectLockRecordDetail.getNum());
                                otherOrg.setCommodityValue(projectLockRecordDetail.getPrice());
                                otherOrg.setIsParking(IsDeleteEnum.YES.getKey());
                                otherOrg.setIsDelete(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsSplit(IsDeleteEnum.NO.getKey());
                                otherOrg.setTotalNum(projectLockRecordDetail.getNum());
                                otherOrg.setCreateTime(now);
                                otherOrg.setUpdateTime(now);

                                collectTotalNum = collectTotalNum + projectLockRecordDetail.getNum();

                                otherOrg.setTotalNum(collectTotalNum);
                                otherInsertList.add(otherOrg);

                                buildOrg.setForsaleParkingNum(projectLockRecordDetail.getNum());
                                buildOrg.setAveragePriceParkingForsale(projectLockRecordDetail.getAveragePrice());
                                buildOrg.setCommodityValue(projectLockRecordDetail.getPrice());
                            }
                        }
                    }

                    //楼栋从新计算信息
                    if (buildIsParking.equals(IsDeleteEnum.NO.getKey())){
                        buildOrg.setNum(collectTotalNum);
                        buildOrg.setTotalNum(collectTotalNum);
                        buildOrg.setTotalSaleArea(collectTotalArea);
                        buildOrg.setRoomNum(collectTotalNum);
                        buildOrg.setSaleArea(collectTotalArea);
                        buildOrg.setHouseCommodityValue(collectTotalPrice);
                        buildOrg.setAveragePriceHouse(StrUtils.bigDecimalDIV(buildOrg.getHouseCommodityValue(), buildOrg.getSaleArea()));

                        buildOrg.setPrice(new BigDecimal(0));
                        buildOrg.setRoomSold(0);
                        buildOrg.setAreaSold(new BigDecimal(0));
                        buildOrg.setPriceSold(new BigDecimal(0));

                        buildOrg.setRoomPriced(0);
                        buildOrg.setAreaPriced(new BigDecimal(0));
                        buildOrg.setPricePriced(new BigDecimal(0));

                        buildOrg.setRoomZc(0);
                        buildOrg.setAreaZc(new BigDecimal(0));
                        buildOrg.setPriceRoomZc(new BigDecimal(0));

                        buildOrg.setIsTotalCollect(IsDeleteEnum.NO.getKey());
                    }else{
                        buildOrg.setParkingNum(collectTotalSaleNum);
                        buildOrg.setNotCommodityValue(collectTotalPrice);
                        buildOrg.setAveragePriceParking(StrUtils.bigDecimalDIV(buildOrg.getNotCommodityValue(), new BigDecimal(buildOrg.getParkingNum())));
                        Integer zcNum = (buildOrg.getTotalNum()==null?0:buildOrg.getTotalNum()) - collectTotalSaleNum
                                - (buildOrg.getForsaleParkingNum()==null?0:buildOrg.getForsaleParkingNum());
                        buildOrg.setParkingZc(zcNum);
                    }

                    buildInsertMap.put(buildOrgId, buildOrg);
                }
            }

            for (Map.Entry<String, PriceValueOrg> buildInsertmap : buildInsertMap.entrySet()){
                buildInsertList.add(buildInsertmap.getValue());
            }

            //货值汇总
            List<PriceValueOrg> groupInsertList = new ArrayList<PriceValueOrg>();
            List<PriceValueOrg> productInsertList = new ArrayList<PriceValueOrg>();
            if (CollectionUtils.isNotEmpty(buildInsertList)){
                for (PriceValueOrg buildOrg : buildInsertList){
                    String pid = buildOrg.getPid();
                    PriceValueOrg valueOrg = productInsertMap.get(pid);
                    if (valueOrg != null){
                        priceVersionValueOrgServiceImpl.valueUpSummary(valueOrg, buildOrg);

                        productInsertMap.put(pid, valueOrg);
                    }
                }

                for (Map.Entry<String, PriceValueOrg> pruductMap : productInsertMap.entrySet()){
                    PriceValueOrg pruductOrg = pruductMap.getValue();
                    String pid = pruductOrg.getPid();
                    PriceValueOrg groupOrg = groupInsertMap.get(pid);
                    if (groupOrg != null){

                        priceVersionValueOrgServiceImpl.valueUpSummary(groupOrg, pruductOrg);

                        groupInsertMap.put(pid, groupOrg);
                    }

                    productInsertList.add(pruductOrg);
                }

                for (Map.Entry<String, PriceValueOrg> groupOrgMap : groupInsertMap.entrySet()){
                    PriceValueOrg groupOrg = groupOrgMap.getValue();
                    if (groupOrg != null){

                        priceVersionValueOrgServiceImpl.valueUpSummary(stageOrg, groupOrg);
                    }

                    groupInsertList.add(groupOrg);
                }
            }
            List<PriceValueOrg> projectList = Arrays.asList(stageOrg);

            try{
                priceVersionBackupsService.refreshSaveInfo(oldPriceVersion, priceVersionBackups, now);
            }catch (Exception e){
                log.error("################ refresh price versionBackups error : "+e);
            }

            //测试保存
            recordUpdateAndSaveInfo(oldPriceVersion, projectList, groupInsertList, productInsertList, buildInsertList, otherInsertList);

            try{
                versionLogService.saveVersionLogInfo(oldPriceVersion.getProjectId(), oldPriceVersion.getProjectfId(), ModuleTypeEunm.PRICE.getKey(), VersionEventEnum.SYS_REFRESH.getKey(), oldPriceVersion.getId(), VersionNameUtils.getVersionName(oldPriceVersion), oldPriceVersion.getVersionState(),
                        oldPriceVersion.getVersionState(), "1", instId, Constants.SYS, now, "货值规划数据刷新", isDifferenceList.toString(), IsDeleteEnum.NO.getKey(), Constants.SYS, now);
            }catch (Exception e){
                log.error("################ refresh price version versionLog error : "+e);
            }

        }catch (Exception e){
            log.error("#########################     priceValueRefreshRecordInfo    error:"+e.getMessage(), e);
        }

        log.info("###########################    规划货值刷新    priceValueRefreshRecordInfo end:"+LocalDateTime.now());
    }

    @Override
    public void recordNoticeRefreshToUnlock(String projectId, LocalDateTime now) {
        //查询项目下分期数量
        List<MdmStage> stages = stageService.selectByProjectId(projectId, IsDeleteEnum.NO.getKey());
        if (CollectionUtils.isNotEmpty(stages)){
            IdmUser sysUser = new IdmUser();
            sysUser.setAlias(Constants.SYS);
            sysUser.setUsercn(Constants.SYS_NAME);

            for (MdmStage stage : stages){
               if (stage != null){
                   String projectFid = stage.getProjectFid();
                   //查询分期战规后是否有需要手动处理的待办，如果有，则不刷新
                   boolean isRefresh = false; 
                   List<SysNotice> notices = sysNoticeService.selectNoticeByProjectFidAndTaskType(projectFid, Arrays.asList(VersionTypeEunm.WARPLAN.getKey(), VersionTypeEunm.DYNAMIC.getKey()), ModuleTypeEunm.PRICE.getKey(), ProcessingStateEnum.UNTREATED.getKey(), IsDeleteEnum.NO.getKey());
                   if(CollectionUtils.isNotEmpty(notices)){
                       isRefresh = true;
                       for (SysNotice sysNotice : notices){
                           String processingMode = sysNotice.getProcessingMode();
                           if (StringUtils.isNotEmpty(processingMode) && processingMode.equals(ProcessingModeEnum.MANUAL.getKey())){
                               isRefresh = false;
                           }
                       }
                   }

                   //刷新战规后货值
                   if(isRefresh){
                       try{
                           priceVersionValueOrgService.panoDynamicVersionChange(projectFid, VersionTypeEunm.DYNAMIC.getKey(), "record", null);

                           //系统将该项目分期之前同类待办设置为无效待办，同时删除新门户该分期之前同类待办
                           sysNoticeService.updateNoticeStateByStageIdAndType(projectFid, ModuleTypeEunm.PRICE.getKey(), VersionTypeEunm.WARPLAN.getKey(), ProcessingStateEnum.PROCESSED.getKey(), Constants.SYS, now , IsDeleteEnum.NO.getKey());
                           sysNoticeService.updateNoticeStateByStageIdAndType(projectFid, ModuleTypeEunm.PRICE.getKey(), VersionTypeEunm.DYNAMIC.getKey(), ProcessingStateEnum.PROCESSED.getKey(), Constants.SYS, now , IsDeleteEnum.NO.getKey());
                       }catch (Exception e){
                           log.error("###################    recordDetail   error:"+e.getMessage(), e);
                       }
                   }

                   //查询分期投资版是否有需要手动处理的待办，如果有，则不刷新
                   boolean isInvestmentRefresh = false;
                   List<SysNotice> investmentNotices = sysNoticeService.selectNoticeByProjectFidAndTaskType(projectFid, Arrays.asList(VersionTypeEunm.INVESTMENT.getKey()), ModuleTypeEunm.PRICE.getKey(), ProcessingStateEnum.UNTREATED.getKey(), IsDeleteEnum.NO.getKey());
                   if(CollectionUtils.isNotEmpty(investmentNotices)){
                       isInvestmentRefresh = true;
                       for (SysNotice sysNotice : investmentNotices){
                           String processingMode = sysNotice.getProcessingMode();
                           if (StringUtils.isNotEmpty(processingMode) && processingMode.equals(ProcessingModeEnum.MANUAL.getKey())){
                               isInvestmentRefresh = false;
                           }
                       }
                   }

                   if(isInvestmentRefresh){
                       try{
                           priceVersionValueOrgService.panoCastDecisionVersionChange(projectFid, null);
                           //系统将该项目分期之前同类待办设置为无效待办，同时删除新门户该分期之前同类待办
                           sysNoticeService.updateNoticeStateByStageIdAndType(projectFid, ModuleTypeEunm.PRICE.getKey(), VersionTypeEunm.INVESTMENT.getKey(), ProcessingStateEnum.PROCESSED.getKey(), Constants.SYS, now , IsDeleteEnum.NO.getKey());
                       }catch (Exception e){
                           log.error("###################    recordDetail   error:"+e.getMessage(), e);
                       }
                   }
               }
            }
        }
    }

    private PanoPlanCastDecisionBO getPanoAppointInfo(PriceVersion recordPriceVersion) {
        //查询指定货值版本中引用楼栋计划信息
        String sourcePlan = recordPriceVersion.getSourcePlan();
        //获取最新的战规版楼栋计划
        return panoplanBuildPlanService.selectById(sourcePlan);
    }

    private MdmBuildAreaBO getAppointMdmInfo(String stageId, PriceVersion recordPriceVersion) {
        String sourceAreaVersionStage = recordPriceVersion.getSourceAreaVersionStage();
        String sourceAreaVersionNum = recordPriceVersion.getSourceAreaVersionNum();
        LocalDateTime sourceAreaSysCreatedTime = recordPriceVersion.getSourceAreaSysCreatedTime();
        String sourceGroupVersionStage = recordPriceVersion.getSourceGroupVersionStage();
        String sourceGroupVersionCode = recordPriceVersion.getSourceGroupVersionCode();
        LocalDateTime sourceGroupCreateTime = recordPriceVersion.getSourceGroupCreateTime();

        //查询指定主数据信息
        MdmBuildAreaBO mdmProductWarPlanBO = buildAreaService.selectAppoint(stageId, sourceAreaVersionStage, sourceAreaVersionNum, sourceAreaSysCreatedTime,
                sourceGroupVersionStage, sourceGroupVersionCode, sourceGroupCreateTime);
        if (mdmProductWarPlanBO == null) {
            throw new MsgException(CodeEnum.NON_APPOINT_GROUPBLD_AREA);
        }
        return mdmProductWarPlanBO;
    }

    private String sysAppointPlanCreateInfo(LocalDateTime now, Set<String> bldPrdIds, String stageId, Map<String, List<ProjectLockRecordDetail>> projectLockRecordDetailMap, MdmStage mdmStage, PriceVersion recordPriceVersion, LocalDate ascriptionDate, String instId) {
        String versionId = "";
        try {

            //查询指定货值版本中引用主数据信息
            MdmBuildAreaBO mdmProductWarPlanBO = getAppointMdmInfo(stageId, recordPriceVersion);

            //查询指定货值版本中引用楼栋计划信息
            PanoPlanCastDecisionBO panoPlanCastDecisionBO = getPanoAppointInfo(recordPriceVersion);

            //全景计划系统最新版楼栋计划项目树与主数据系统最新版面积版本项目树不匹配，不允许创建新版本；
            priceVersionValueOrgServiceImpl.mdmToPanoGroupVerification(panoPlanCastDecisionBO, mdmProductWarPlanBO);

            priceVersionValueOrgServiceImpl.mdmToPanoProductVerification(panoPlanCastDecisionBO, mdmProductWarPlanBO);

            Map<String, String> panoplanBuildPlanItemMap = new HashMap<>();
            Map<String, PanoplanBuildPlanItem> panoplanItemMap = new HashMap<>();
            priceVersionValueOrgServiceImpl.mdmToPanoBuildVerification(panoPlanCastDecisionBO, mdmProductWarPlanBO, panoplanBuildPlanItemMap, panoplanItemMap);

            //楼栋计划匹配节点
            Map<String, LocalDateTime> openTimeMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> openTimeActualMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> advanceSaleTimeMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> advanceSaleTimeActualMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> supplyTimeMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> supplyTimeActualMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> supplyTimeVirtualMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> openSaleTimeMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> openSaleTimeActualMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> cappingTimeMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> cappingTimeActualMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> completedTimeMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> completedTimeActualMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> carryOverTimeMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> carryOverTimeActualMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> actualDeliveryTimeMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> actualDeliveryTimeActualMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> contractDeliveryTimeMap = new HashMap<String, LocalDateTime>();
            Map<String, LocalDateTime> contractDeliveryTimeActualMap = new HashMap<String, LocalDateTime>();
            priceVersionValueOrgServiceImpl.panoTimeItemNodeMapInfo(panoPlanCastDecisionBO, panoplanBuildPlanItemMap, openTimeMap, openTimeActualMap, advanceSaleTimeMap, advanceSaleTimeActualMap, supplyTimeMap, supplyTimeActualMap, supplyTimeVirtualMap, openSaleTimeMap, openSaleTimeActualMap, cappingTimeMap, cappingTimeActualMap, completedTimeMap, completedTimeActualMap, carryOverTimeMap, carryOverTimeActualMap, actualDeliveryTimeMap, actualDeliveryTimeActualMap, contractDeliveryTimeMap, contractDeliveryTimeActualMap);

            //分期有可售或阶段性自持产品构成没有批次或供货日期时，不允许新建该分期价格版本
            priceVersionValueOrgServiceImpl.buildBusinessTypeVerificationByNode(panoPlanCastDecisionBO, panoplanBuildPlanItemMap, supplyTimeMap, supplyTimeActualMap, supplyTimeVirtualMap);

            //查询取数系统
            String fetchSysId = recordPriceVersion.getCountingSystemId();
            String fetchSysCode = recordPriceVersion.getCountingSystemCode();

            LocalDateTime fetchTime = recordPriceVersion.getCountingTime();

            //查询本月审批通过和自动生成动态版的版本信息
            String oldVersionId = "";
            String oldVersionNum = "";
            PriceVersion priceVersion = priceVersionService.selectNewestVersionByFidAndDate(stageId, Arrays.asList(VersionTypeEunm.DYNAMIC.getKey()), Arrays.asList(VersionStatusEnum.SUCCESSAPPROVED.getKey(), VersionStatusEnum.SYSGENERATION.getKey()), IsDeleteEnum.NO.getKey(), now);
            if(priceVersion != null){
                if (priceVersion.getVersionType().equals(VersionTypeEunm.DYNAMIC.getKey())){
                    LocalDate preAscriptionDate = priceVersion.getAscriptionDate();
                    if(preAscriptionDate != null){
                        Month preMonth = preAscriptionDate.getMonth();
                        Month month = ascriptionDate.getMonth();
                        if(preMonth.equals(month)){
                            oldVersionId = priceVersion.getId();
                            oldVersionNum = priceVersion.getVersionNum();
                        }
                    }
                }else{
                    oldVersionId = priceVersion.getId();
                    oldVersionNum = priceVersion.getVersionNum();
                }
            }

            //创建新版本
            PriceVersion newVersion = priceVersionValueOrgServiceImpl.createVersionInfo(stageId, VersionTypeEunm.DYNAMIC.getKey(), VersionCreateEnum.AUTOMATICCREATE.getKey(), Constants.SYS, mdmStage, ascriptionDate, oldVersionId, oldVersionNum, 7,
                    mdmProductWarPlanBO, panoPlanCastDecisionBO, 0, recordPriceVersion.getId(), fetchTime, fetchSysCode, fetchSysId, recordPriceVersion.getIsMarket(), now,WhetherEnum.NO.getKey());
            versionId = newVersion.getId();

            PriceVersionBackups priceVersionBackups = new PriceVersionBackups();
            BeanUtils.copyProperties(newVersion, priceVersionBackups);
            priceVersionBackups.setVersionId(newVersion.getId());
            priceVersionBackups.setId(UUIDUtils.create());

            //复制分期
            QueryWrapper<PriceValueOrg> stageQueryWrapper = new QueryWrapper<PriceValueOrg>();
            stageQueryWrapper.eq("version_id", recordPriceVersion.getId())
                    .eq("type", OrgTypeEunm.ORG_STAGE.getKey())
                    .eq("is_delete", IsDeleteEnum.NO.getKey());
            PriceValueOrg recordStageOrg = priceValueOrgService.getOne(stageQueryWrapper);
            PriceValueOrg stageOrg = new PriceValueOrg();
            BeanUtils.copyProperties(recordStageOrg, stageOrg);
            stageOrg.setId(UUIDUtils.create());
            stageOrg.setVersionId(newVersion.getId());
            stageOrg.setCreateTime(now);
            stageOrg.setUpdateTime(now);
            initBuildBasicInfo(stageOrg);

            //复制组团
            Map<String, PriceValueOrg> recordKeyGroupMap = new HashMap<String, PriceValueOrg>();
            QueryWrapper<PriceValueOrg> groupQueryWrapper = new QueryWrapper<PriceValueOrg>();
            groupQueryWrapper.eq("version_id", recordPriceVersion.getId())
                    .eq("type", OrgTypeEunm.ORG_GROUP.getKey())
                    .eq("is_delete", IsDeleteEnum.NO.getKey());
            List<PriceValueOrg> recordGroupOrgs = priceValueOrgService.list(groupQueryWrapper);
            for (PriceValueOrg recordGroupOrg : recordGroupOrgs){
                PriceValueOrg groupOrg = new PriceValueOrg();
                BeanUtils.copyProperties(recordGroupOrg, groupOrg);
                groupOrg.setId(UUIDUtils.create());
                groupOrg.setVersionId(newVersion.getId());
                groupOrg.setPid(stageOrg.getId());
                groupOrg.setCreateTime(now);
                groupOrg.setUpdateTime(now);
                initBuildBasicInfo(groupOrg);

                recordKeyGroupMap.put(recordGroupOrg.getId(), groupOrg);
            }

            //复制产品构成
            Map<String, PriceValueOrg> groupInsertMap = new HashMap<String, PriceValueOrg>();
            Map<String, PriceValueOrg> recordKeyProductMap = new HashMap<String, PriceValueOrg>();
            QueryWrapper<PriceValueOrg> productQueryWrapper = new QueryWrapper<PriceValueOrg>();
            productQueryWrapper.eq("version_id", recordPriceVersion.getId())
                    .eq("type", OrgTypeEunm.ORG_PRODUCT.getKey())
                    .eq("is_delete", IsDeleteEnum.NO.getKey());
            List<PriceValueOrg> recordProductOrgs = priceValueOrgService.list(productQueryWrapper);
            for (PriceValueOrg recordProductOrg : recordProductOrgs){
                PriceValueOrg productOrg = new PriceValueOrg();
                BeanUtils.copyProperties(recordProductOrg, productOrg);
                productOrg.setId(UUIDUtils.create());
                productOrg.setVersionId(newVersion.getId());
                productOrg.setCreateTime(now);
                productOrg.setUpdateTime(now);
                initBuildBasicInfo(productOrg);

                PriceValueOrg groupOrg = recordKeyGroupMap.get(recordProductOrg.getPid());
                productOrg.setPid(groupOrg.getId());

                groupInsertMap.put(groupOrg.getId(), groupOrg);
                recordKeyProductMap.put(recordProductOrg.getId(), productOrg);
            }

            //复制面积段和车位
            Map<String, List<PriceValueOrg>> otherItemMap = new HashMap<String, List<PriceValueOrg>>();
            Map<String, PriceValueOrg> oldBuildItemMap = new HashMap<String, PriceValueOrg>();
            Map<String, PriceValueOrg> buildItemMap = new HashMap<String, PriceValueOrg>();
            QueryWrapper<PriceValueOrg> otherQueryWrapper = new QueryWrapper<PriceValueOrg>();
            otherQueryWrapper.eq("version_id", recordPriceVersion.getId())
                    .in("type", OrgTypeEunm.ORG_HOUSE_PACKAGE.getKey(),OrgTypeEunm.ORG_SALE_PACKAGE.getKey(),
                            OrgTypeEunm.ORG_NOT_SALE_PACKAGE.getKey(),OrgTypeEunm.ORG_SALING_PARKING.getKey(),OrgTypeEunm.ORG_NOT_SALING_PARKING.getKey())
                    .eq("is_delete", IsDeleteEnum.NO.getKey());
            List<PriceValueOrg> recordOtherOrgs = priceValueOrgService.list(otherQueryWrapper);
            if(CollectionUtils.isNotEmpty(recordOtherOrgs)){
                for (PriceValueOrg recordOtherOrg : recordOtherOrgs){
                    PriceValueOrg otherOrg = new PriceValueOrg();
                    BeanUtils.copyProperties(recordOtherOrg, otherOrg);
                    otherOrg.setId(UUIDUtils.create());
                    otherOrg.setVersionId(newVersion.getId());
                    otherOrg.setCreateTime(now);
                    otherOrg.setUpdateTime(now);

                    List<PriceValueOrg> orgList = otherItemMap.get(otherOrg.getPid());
                    if (CollectionUtils.isEmpty(orgList)){
                        orgList = new ArrayList<PriceValueOrg>();
                    }
                    orgList.add(otherOrg);
                    otherItemMap.put(otherOrg.getPid(), orgList);
                }
            }

            //复制楼栋
            Map<String, PriceValueOrg> productInsertMap = new HashMap<String, PriceValueOrg>();
            Map<String, PriceValueOrg> recordKeyBuildMap = new HashMap<String, PriceValueOrg>();
            QueryWrapper<PriceValueOrg> buildQueryWrapper = new QueryWrapper<PriceValueOrg>();
            buildQueryWrapper.eq("version_id", recordPriceVersion.getId())
                    .eq("type", OrgTypeEunm.ORG_BUILD.getKey())
                    .eq("is_delete", IsDeleteEnum.NO.getKey());
            List<PriceValueOrg> recordBuildOrgs = priceValueOrgService.list(buildQueryWrapper);
            for (PriceValueOrg recordBuildOrg : recordBuildOrgs){
                PriceValueOrg buildOrg = new PriceValueOrg();
                PropertyUtils.copyProperties(buildOrg, recordBuildOrg);
                buildOrg.setId(UUIDUtils.create());
                buildOrg.setVersionId(newVersion.getId());
                buildOrg.setCreateTime(now);
                buildOrg.setUpdateTime(now);

                PriceValueOrg productOrg = recordKeyProductMap.get(recordBuildOrg.getPid());
                buildOrg.setPid(productOrg.getId());

                buildItemMap.put(buildOrg.getOrgId(), buildOrg);
                oldBuildItemMap.put(recordBuildOrg.getOrgId(), recordBuildOrg);

                List<PriceValueOrg> orgList = otherItemMap.get(recordBuildOrg.getId());
                if (CollectionUtils.isNotEmpty(orgList)){
                    for (PriceValueOrg otherOrg: orgList){
                        otherOrg.setPid(buildOrg.getId());

                        List<PriceValueOrg> newOrgList = otherItemMap.get(otherOrg.getPid());
                        if (CollectionUtils.isEmpty(newOrgList)){
                            newOrgList = new ArrayList<PriceValueOrg>();
                        }
                        newOrgList.add(otherOrg);
                        otherItemMap.put(otherOrg.getPid(), newOrgList);
                    }
                }

                productInsertMap.put(productOrg.getId(), productOrg);
                recordKeyBuildMap.put(recordBuildOrg.getId(), buildOrg);
            }

            List<PriceValueOrg> buildInsertList =new ArrayList<PriceValueOrg>();
            List<PriceValueOrg> otherInsertList = new ArrayList<PriceValueOrg>();
            Map<String, PriceValueOrg> buildInsertMap = new HashMap<String, PriceValueOrg>();
            for (Map.Entry<String, PriceValueOrg> buildItemmap : buildItemMap.entrySet()){

                PriceValueOrg buildOrg = buildItemmap.getValue();
                String buildId = buildOrg.getId();
                String buildOrgId = buildOrg.getOrgId();
                Integer buildIsParking = buildOrg.getIsParking();

                if(!bldPrdIds.contains(buildOrgId)){
                    buildInsertMap.put(buildOrgId, buildOrg);

                    List<PriceValueOrg> orgList = otherItemMap.get(buildOrg.getId());
                    if(CollectionUtils.isNotEmpty(orgList)){
                        for (PriceValueOrg org : orgList){
                            org.setId(UUIDUtils.create());
                            org.setVersionId(buildOrg.getVersionId());
                            org.setPid(buildId);
                            org.setCreateTime(now);
                            org.setUpdateTime(now);

                            otherInsertList.add(org);
                        }
                    }
                    continue;
                }

                //刷新规划货值
                List<ProjectLockRecordDetail> recordDetailList = projectLockRecordDetailMap.get(buildOrg.getOrgId());
                if (CollectionUtils.isNotEmpty(recordDetailList)) {

                    Integer collectTotalNum = 0;
                    Integer collectTotalSaleNum = 0;
                    BigDecimal collectTotalArea = new BigDecimal(0);
                    BigDecimal collectTotalPrice = new BigDecimal(0);

                    for (ProjectLockRecordDetail projectLockRecordDetail : recordDetailList){
                        PriceValueOrg otherOrg = new PriceValueOrg();
                        otherOrg.setId(UUIDUtils.create());
                        otherOrg.setVersionId(buildOrg.getVersionId());
                        otherOrg.setPid(buildId);
                        otherOrg.setType(projectLockRecordDetail.getType());

                        if (buildIsParking.equals(IsDeleteEnum.NO.getKey())){
                            if(projectLockRecordDetail.getType().equals(OrgTypeEunm.ORG_HOUSE_PACKAGE.getKey())){
                                otherOrg.setOrgCode(OrgTypeEunm.ORG_HOUSE_PACKAGE.getKey());
                                otherOrg.setOrgName(projectLockRecordDetail.getName());
                                otherOrg.setAreaPart(projectLockRecordDetail.getName());
                                otherOrg.setNum(projectLockRecordDetail.getNum());
                                otherOrg.setRoomNum(projectLockRecordDetail.getNum());
                                otherOrg.setSaleArea(projectLockRecordDetail.getArea());
                                otherOrg.setAveragePriceHouse(projectLockRecordDetail.getAveragePrice());
                                otherOrg.setHouseCommodityValue(projectLockRecordDetail.getPrice());
                                otherOrg.setIsParking(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsDelete(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsSplit(IsDeleteEnum.NO.getKey());
                                otherOrg.setTotalNum(projectLockRecordDetail.getNum());
                                otherOrg.setTotalSaleArea(projectLockRecordDetail.getArea());
                                otherOrg.setCreateTime(now);
                                otherOrg.setUpdateTime(now);

                                otherInsertList.add(otherOrg);

                                collectTotalNum = collectTotalNum + projectLockRecordDetail.getNum();
                                collectTotalArea = StrUtils.BigDecimalADD(collectTotalArea, projectLockRecordDetail.getArea());
                                collectTotalPrice = StrUtils.BigDecimalADD(collectTotalPrice, projectLockRecordDetail.getPrice());
                            }
                        }else{
                            if(projectLockRecordDetail.getType().equals(OrgTypeEunm.ORG_SALE_PACKAGE.getKey())){
                                otherOrg.setOrgCode(OrgTypeEunm.ORG_SALE_PACKAGE.getKey());
                                otherOrg.setOrgName(OrgTypeEunm.ORG_SALE_PACKAGE.getValue());
                                otherOrg.setIsSale(IsDeleteEnum.YES.getKey());
                                otherOrg.setNum(projectLockRecordDetail.getNum());
                                otherOrg.setParkingNum(projectLockRecordDetail.getNum());
                                otherOrg.setAveragePriceParking(projectLockRecordDetail.getAveragePrice());
                                otherOrg.setNotCommodityValue(projectLockRecordDetail.getPrice());
                                otherOrg.setPrice(projectLockRecordDetail.getPrice());
                                otherOrg.setPriceSold(projectLockRecordDetail.getPrice());
                                otherOrg.setParkingSold(projectLockRecordDetail.getNum());
                                otherOrg.setIsParking(IsDeleteEnum.YES.getKey());
                                otherOrg.setIsDelete(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsSplit(IsDeleteEnum.NO.getKey());
                                otherOrg.setCreateTime(now);
                                otherOrg.setUpdateTime(now);

                                collectTotalNum = collectTotalNum + projectLockRecordDetail.getNum();
                                collectTotalSaleNum = collectTotalSaleNum + projectLockRecordDetail.getNum();

                                otherOrg.setTotalNum(collectTotalNum);
                                otherInsertList.add(otherOrg);

                                collectTotalPrice = StrUtils.BigDecimalADD(collectTotalPrice, projectLockRecordDetail.getPrice());

                                buildOrg.setParkingSold(projectLockRecordDetail.getNum());
                                buildOrg.setPrice(StrUtils.BigDecimalADD(buildOrg.getPrice(), projectLockRecordDetail.getPrice()));
                                buildOrg.setPriceSold(projectLockRecordDetail.getPrice());

                            }else if(projectLockRecordDetail.getType().equals(OrgTypeEunm.ORG_NOT_SALE_PACKAGE.getKey())){
                                otherOrg.setOrgCode(OrgTypeEunm.ORG_NOT_SALE_PACKAGE.getKey());
                                otherOrg.setOrgName(OrgTypeEunm.ORG_NOT_SALE_PACKAGE.getValue());
                                otherOrg.setIsSale(IsDeleteEnum.NO.getKey());
                                otherOrg.setNum(projectLockRecordDetail.getNum());
                                otherOrg.setParkingNum(projectLockRecordDetail.getNum());
                                otherOrg.setAveragePriceParking(projectLockRecordDetail.getAveragePrice());
                                otherOrg.setNotCommodityValue(projectLockRecordDetail.getPrice());
                                otherOrg.setPrice(projectLockRecordDetail.getPrice());
                                otherOrg.setPricePriced(projectLockRecordDetail.getPrice());
                                otherOrg.setParkingPriced(projectLockRecordDetail.getNum());
                                otherOrg.setIsParking(IsDeleteEnum.YES.getKey());
                                otherOrg.setIsDelete(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsSplit(IsDeleteEnum.NO.getKey());
                                otherOrg.setCreateTime(now);
                                otherOrg.setUpdateTime(now);

                                collectTotalNum = collectTotalNum + projectLockRecordDetail.getNum();
                                collectTotalSaleNum = collectTotalSaleNum + projectLockRecordDetail.getNum();

                                otherOrg.setTotalNum(collectTotalNum);
                                otherInsertList.add(otherOrg);

                                collectTotalPrice = StrUtils.BigDecimalADD(collectTotalPrice, projectLockRecordDetail.getPrice());

                                buildOrg.setParkingPriced(projectLockRecordDetail.getNum());
                                buildOrg.setPrice(StrUtils.BigDecimalADD(buildOrg.getPrice(), projectLockRecordDetail.getPrice()));
                                buildOrg.setPricePriced(projectLockRecordDetail.getPrice());
                            }else if(projectLockRecordDetail.getType().equals(OrgTypeEunm.ORG_SALING_PARKING.getKey())){
                                otherOrg.setOrgCode(OrgTypeEunm.ORG_SALING_PARKING.getKey());
                                otherOrg.setOrgName(OrgTypeEunm.ORG_SALING_PARKING.getValue());
                                otherOrg.setNum(projectLockRecordDetail.getNum());
                                otherOrg.setParkingNum(projectLockRecordDetail.getNum());
                                otherOrg.setAveragePriceParking(projectLockRecordDetail.getAveragePrice());
                                otherOrg.setNotCommodityValue(projectLockRecordDetail.getPrice());
                                otherOrg.setIsParking(IsDeleteEnum.YES.getKey());
                                otherOrg.setIsDelete(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsSplit(IsDeleteEnum.NO.getKey());
                                otherOrg.setCreateTime(now);
                                otherOrg.setUpdateTime(now);

                                collectTotalNum = collectTotalNum + projectLockRecordDetail.getNum();
                                collectTotalSaleNum = collectTotalSaleNum + projectLockRecordDetail.getNum();
                                collectTotalPrice = StrUtils.BigDecimalADD(collectTotalPrice, projectLockRecordDetail.getPrice());

                                otherOrg.setTotalNum(collectTotalNum);
                                otherInsertList.add(otherOrg);

                            }else if (projectLockRecordDetail.getType().equals(OrgTypeEunm.ORG_NOT_SALING_PARKING.getKey())){
                                otherOrg.setOrgCode(OrgTypeEunm.ORG_NOT_SALING_PARKING.getKey());
                                otherOrg.setOrgName(OrgTypeEunm.ORG_NOT_SALING_PARKING.getValue());
                                otherOrg.setNum(projectLockRecordDetail.getNum());
                                otherOrg.setAveragePriceParkingForsale(projectLockRecordDetail.getAveragePrice());
                                otherOrg.setForsaleParkingNum(projectLockRecordDetail.getNum());
                                otherOrg.setCommodityValue(projectLockRecordDetail.getPrice());
                                otherOrg.setIsParking(IsDeleteEnum.YES.getKey());
                                otherOrg.setIsDelete(IsDeleteEnum.NO.getKey());
                                otherOrg.setIsSplit(IsDeleteEnum.NO.getKey());
                                otherOrg.setTotalNum(projectLockRecordDetail.getNum());
                                otherOrg.setCreateTime(now);
                                otherOrg.setUpdateTime(now);

                                collectTotalNum = collectTotalNum + projectLockRecordDetail.getNum();

                                otherOrg.setTotalNum(collectTotalNum);
                                otherInsertList.add(otherOrg);

                                buildOrg.setForsaleParkingNum(projectLockRecordDetail.getNum());
                                buildOrg.setAveragePriceParkingForsale(projectLockRecordDetail.getAveragePrice());
                                buildOrg.setCommodityValue(projectLockRecordDetail.getPrice());
                            }
                        }
                    }

                    //楼栋从新计算信息
                    if (buildIsParking.equals(IsDeleteEnum.NO.getKey())){
                        buildOrg.setNum(collectTotalNum);
                        buildOrg.setTotalNum(collectTotalNum);
                        buildOrg.setTotalSaleArea(collectTotalArea);
                        buildOrg.setRoomNum(collectTotalNum);
                        buildOrg.setSaleArea(collectTotalArea);
                        buildOrg.setHouseCommodityValue(collectTotalPrice);
                        buildOrg.setAveragePriceHouse(StrUtils.bigDecimalDIV(buildOrg.getHouseCommodityValue(), buildOrg.getSaleArea()));

                        buildOrg.setPrice(new BigDecimal(0));
                        buildOrg.setRoomSold(0);
                        buildOrg.setAreaSold(new BigDecimal(0));
                        buildOrg.setPriceSold(new BigDecimal(0));

                        buildOrg.setRoomPriced(0);
                        buildOrg.setAreaPriced(new BigDecimal(0));
                        buildOrg.setPricePriced(new BigDecimal(0));

                        buildOrg.setRoomZc(0);
                        buildOrg.setAreaZc(new BigDecimal(0));
                        buildOrg.setPriceRoomZc(new BigDecimal(0));

                        buildOrg.setIsTotalCollect(IsDeleteEnum.NO.getKey());
                    }else{
                        buildOrg.setParkingNum(collectTotalSaleNum);
                        buildOrg.setNotCommodityValue(collectTotalPrice);
                        buildOrg.setAveragePriceParking(StrUtils.bigDecimalDIV(buildOrg.getNotCommodityValue(), new BigDecimal(buildOrg.getParkingNum())));
                        Integer zcNum = (buildOrg.getTotalNum()==null?0:buildOrg.getTotalNum()) - collectTotalSaleNum
                                - (buildOrg.getForsaleParkingNum()==null?0:buildOrg.getForsaleParkingNum());
                        buildOrg.setParkingZc(zcNum);
                    }

                    buildInsertMap.put(buildOrgId, buildOrg);
                }
            }

            for (Map.Entry<String, PriceValueOrg> buildInsertmap : buildInsertMap.entrySet()){
                buildInsertList.add(buildInsertmap.getValue());
            }

            //货值汇总
            List<PriceValueOrg> groupInsertList = new ArrayList<PriceValueOrg>();
            List<PriceValueOrg> productInsertList = new ArrayList<PriceValueOrg>();
            if (CollectionUtils.isNotEmpty(buildInsertList)){
                for (PriceValueOrg buildOrg : buildInsertList){
                    String pid = buildOrg.getPid();
                    PriceValueOrg valueOrg = productInsertMap.get(pid);
                    if (valueOrg != null){
                        priceVersionValueOrgServiceImpl.valueUpSummary(valueOrg, buildOrg);

                        productInsertMap.put(pid, valueOrg);
                    }
                }

                for (Map.Entry<String, PriceValueOrg> pruductMap : productInsertMap.entrySet()){
                    PriceValueOrg pruductOrg = pruductMap.getValue();
                    String pid = pruductOrg.getPid();
                    PriceValueOrg groupOrg = groupInsertMap.get(pid);
                    if (groupOrg != null){

                        priceVersionValueOrgServiceImpl.valueUpSummary(groupOrg, pruductOrg);

                        groupInsertMap.put(pid, groupOrg);
                    }

                    productInsertList.add(pruductOrg);
                }

                for (Map.Entry<String, PriceValueOrg> groupOrgMap : groupInsertMap.entrySet()){
                    PriceValueOrg groupOrg = groupOrgMap.getValue();
                    if (groupOrg != null){

                        priceVersionValueOrgServiceImpl.valueUpSummary(stageOrg, groupOrg);
                    }

                    groupInsertList.add(groupOrg);
                }
            }
            List<PriceValueOrg> projectList = Arrays.asList(stageOrg);

            try{
                priceVersionBackupsService.refreshSaveInfo(recordPriceVersion, priceVersionBackups ,now);
            }catch (Exception e){
                log.error("################ refresh price versionBackups error : "+e);
            }

            //测试保存
            recordSaveInfo(newVersion, projectList, groupInsertList, productInsertList, buildInsertList, otherInsertList);

            try{
                versionLogService.saveVersionLogInfo(mdmStage.getProjectId(), mdmStage.getProjectFid(), ModuleTypeEunm.PRICE.getKey(), newVersion.getVersionCreateState().equals(VersionCreateEnum.MANUALCREATE.getKey())?VersionEventEnum.MANUALCREATE.getKey():VersionEventEnum.SYS_GENERATE.getKey(),
                        newVersion.getId(), VersionNameUtils.getVersionName(newVersion), null,
                        newVersion.getVersionState(), "1", instId, Constants.SYS, now, "货值规划货值创建版本", null, IsDeleteEnum.NO.getKey(), Constants.SYS, now);
            }catch (Exception e){
                log.error("################  record create price version versionLog error : "+e);
            }
        } catch (Exception e) {
            log.error("###################   货值自动生成:"+e.getMessage(), e);
        }

        return versionId;
    }

    private void initBuildBasicInfo(PriceValueOrg buildOrg) {
        buildOrg.setNum(0);
        buildOrg.setRoomNum(0);
        buildOrg.setParkingNum(0);
        buildOrg.setForsaleParkingNum(0);
        buildOrg.setTotalNum(0);
        buildOrg.setPrice(new BigDecimal(0));
        buildOrg.setSaleArea(new BigDecimal(0));
        buildOrg.setTotalSaleArea(new BigDecimal(0));
        buildOrg.setAveragePriceHouse(new BigDecimal(0));
        buildOrg.setAveragePriceParking(new BigDecimal(0));
        buildOrg.setAveragePriceParkingForsale(new BigDecimal(0));
        buildOrg.setHouseCommodityValue(new BigDecimal(0));
        buildOrg.setNotCommodityValue(new BigDecimal(0));
        buildOrg.setCommodityValue(new BigDecimal(0));

        buildOrg.setRoomSold(0);
        buildOrg.setParkingSold(0);
        buildOrg.setAreaSold(new BigDecimal(0));
        buildOrg.setPriceSold(new BigDecimal(0));

        buildOrg.setRoomPriced(0);
        buildOrg.setParkingPriced(0);
        buildOrg.setAreaPriced(new BigDecimal(0));
        buildOrg.setPricePriced(new BigDecimal(0));

        buildOrg.setRoomZc(0);
        buildOrg.setParkingZc(0);
        buildOrg.setAreaZc(new BigDecimal(0));
        buildOrg.setPriceRoomZc(new BigDecimal(0));
        buildOrg.setPriceParkingZc(new BigDecimal(0));

        buildOrg.setIsTotalCollect(IsDeleteEnum.YES.getKey());
    }

    @Transactional(rollbackFor=Exception.class)
    private void recordUpdateAndSaveInfo(PriceVersion oldPriceVersion, List<PriceValueOrg> projectList, List<PriceValueOrg> groupInsertList, List<PriceValueOrg> productInsertList, List<PriceValueOrg> buildInsertList, List<PriceValueOrg> otherInsertList) {

        QueryWrapper<PriceValueOrg> orgWrapper = new QueryWrapper<PriceValueOrg>();
        orgWrapper.eq("version_id", oldPriceVersion.getId())
                .eq("is_delete", IsDeleteEnum.NO.getKey());

        //删除之前货值信息
        priceVersionMapper.updateByPrimaryKeySelective(oldPriceVersion);

        //测试保存
        priceValueOrgMapper.delete(orgWrapper);
        priceValueOrgMapper.insertBatch(projectList);
        if (CollectionUtils.isNotEmpty(groupInsertList)) {
            priceValueOrgMapper.insertBatch(groupInsertList);
        }
        if (CollectionUtils.isNotEmpty(productInsertList)) {
            priceValueOrgMapper.insertBatch(productInsertList);
        }
        if (CollectionUtils.isNotEmpty(buildInsertList)) {
            priceValueOrgMapper.insertBatch(buildInsertList);
        }
        if (CollectionUtils.isNotEmpty(otherInsertList)) {
            priceValueOrgMapper.insertBatch(otherInsertList);
        }
    }

    @Transactional(rollbackFor=Exception.class)
    private void recordSaveInfo(PriceVersion newVersion, List<PriceValueOrg> projectList, List<PriceValueOrg> groupInsertList, List<PriceValueOrg> productInsertList, List<PriceValueOrg> buildInsertList, List<PriceValueOrg> otherInsertList) {

        //测试保存
        priceVersionMapper.insertRecord(newVersion);
        priceValueOrgMapper.insertBatch(projectList);
        if (CollectionUtils.isNotEmpty(groupInsertList)) {
            priceValueOrgMapper.insertBatch(groupInsertList);
        }
        if (CollectionUtils.isNotEmpty(productInsertList)) {
            priceValueOrgMapper.insertBatch(productInsertList);
        }
        if (CollectionUtils.isNotEmpty(buildInsertList)) {
            priceValueOrgMapper.insertBatch(buildInsertList);
        }
        if (CollectionUtils.isNotEmpty(otherInsertList)) {
            priceValueOrgMapper.insertBatch(otherInsertList);
        }
    }
}
